<template>
  <div ref="wrapper">
    <div class="content">
      <slot></slot>
    </div>
  </div>
</template>

<script>
import BScroll from 'better-scroll'
export default {
  name:'Scroll',
  props:{
    probeType:{
      type:Number,
      default:0
    },
    // click:{
    //   type:boolean,
    //   default:true
    // }
    pullUpLoad:{
      type:Boolean,
      default:true
    },
  },
  data(){
    return{
      scroll:null
    }
  },
  methods:{
    initScroll(){
      this.scroll = new BScroll(this.$refs.wrapper,{
        probeType:this.probeType,
        click:true,
        pullUpLoad :this.pullUpLoad,
        // ObserveDom:true,
        observeImage:true
      })
      
      
      if(this.probeType === 2 || this.probeType === 3){
        this.scroll.on('scroll',position =>{
          this.$emit('scroll',position)
        })
      }
      if(this.pullUpLoad){
        this.scroll.on('pullingUp',()=>{
          this.$emit('pullingUp')
        })
      }
    },
    scrollTo(x,y,time=300){
      this.scroll && this.scroll.scrollTo(x,y,time)
      // console.log(this.scroll)
    },
    refresh(){
      this.scroll && this.scroll.refresh()
    },
    finishPullUp(){
      this.scroll && this.scroll.finishPullUp()
    },
    getScrollY(){
      return this.scroll ? this.scroll.y : 0
    }
  },
  mounted(){
    // console.log(this.$refs.wrapper)
    // setTimeout(() => {
      this.initScroll()

    // }, 50);
  }

}
</script>

<style scoped>

</style>